import { request } from '@/utils'

// 登录接口
export function login(data) {
  return request({
    url: '/public/login',
    method: 'post',
    data,
  })
}

// 注册接口
export function register(data) {
  return request({
    url: '/public/register',
    method: 'post',
    data,
  })
}

// 添加图书馆
export function addLibrary(data) {
  return request({
    url: '/library/add',
    method: 'post',
    data,
  })
}

// 获取图书馆列表
export function getLibraryList(params) {
  return request({
    url: '/library/all',
    method: 'get',
    params,
  })
}

// 获取管理员列表
export function getAdminList(params) {
  return request({
    url: '/admins',
    method: 'get',
    params,
  })
}

// 添加管理员
export function addAdmin(data) {
  return request({
    url: '/admin/add',
    method: 'post',
    data,
  })
}

// 删除管理员
export function deleteAdmin(params) {
  return request({
    url: '/admin/delete',
    method: 'delete',
    params,
  })
}

// 切换状态
export function changeAdminStatus(params) {
  return request({
    url: '/admin/status',
    method: 'post',
    params,
  })
}

// 重置密码
export function resetPassword(params) {
  return request({
    url: '/password/reset',
    method: 'post',
    params,
  })
}

// 获取图书馆房间列表
export function getRoomList(params) {
  return request({
    url: '/library/rooms',
    method: 'get',
    params,
  })
}

// 添加房间
export function addRoom(data) {
  return request({
    url: '/room/add',
    method: 'post',
    data,
  })
}

// 更新房间布局
export function updateRoom(data) {
  return request({
    url: '/room/update',
    method: 'post',
    data,
  })
}

// 添加座位
export function addSeat(data) {
  return request({
    url: '/seat/add',
    method: 'post',
    data,
  })
}

// 添加书架
export function addBookshelf(data) {
  return request({
    url: '/bookshelf/add',
    method: 'post',
    data,
  })
}

// 获取所有用户
export function getUserList(params) {
  return request({
    url: '/users',
    method: 'get',
    params,
  })
}

// 修改用户状态
export function changeUserStatus(params) {
  return request({
    url: '/user/status',
    method: 'post',
    params,
  })
}

// 获取所有讲座
export function getLectureList(params) {
  return request({
    url: '/lectures',
    method: 'get',
    params,
  })
}

// 添加讲座
export function addLecture(data) {
  return request({
    url: '/lecturer/add',
    method: 'post',
    data,
  })
}

// 获取所有图书分类
export function getCategoryList(params) {
  return request({
    url: '/books/categories',
    method: 'get',
    params,
  })
}

// 获取所有图书
export function getBookList(params) {
  return request({
    url: '/books/page',
    method: 'get',
    params,
  })
}

// 添加图书
export function addBook(data) {
  return request({
    url: '/book/add',
    method: 'post',
    data,
  })
}

// 获取所有图书副本
export function getBookCopyList(id) {
  return request({
    url: `/book-copy/book/${id}`,
    method: 'get',
  })
}

// 新增副本
export function addBookCopy(data) {
  return request({
    url: '/book-copy/add',
    method: 'post',
    data,
  })
}

// 删除副本
export function deleteBookCopy(params) {
  return request({
    url: '/book-copy/delete',
    method: 'post',
    params,
  })
}

// 获取书架树形结构
export function getbookShelfTree(params) {
  return request({
    url: '/library/bookshelfs',
    method: 'get',
    params,
  })
}

//获取当前登录用户信息
export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get',
  })
}

//更新当前用户信息
export function updateUserInfo(data) {
  return request({
    url: '/user/update',
    method: 'post',
    data,
  })
}

//修改密码
export function changePassword(data) {
  return request({
    url: '/user/changePassword',
    method: 'post',
    data,
  })
}

// 借阅图书
export function borrowBook(data) {
  return request({
    url: '/borrow',
    method: 'post',
    data,
  })
}

// 讲座报名
export function registerLecture(id) {
  return request({
    url: `/lectures/${id}/register`,
    method: 'post',
  })
}

// 座位预约详情
export function getSeatDetail(id) {
  return request({
    url: `/seats/${id}/reservations/today`,
    method: 'get',
  })
}

// 座位预约
export function reservation(data) {
  return request({
    url: '/reservations',
    method: 'post',
    data,
  })
}

// 查询我的预约记录
export function getMyReservationList(params) {
  return request({
    url: '/reservations/my',
    method: 'get',
    params,
  })
}

// 查询我的报名记录
export function getMyRegistrationList(params) {
  return request({
    url: '/lectures/my-registrations',
    method: 'get',
    params,
  })
}

// 查询我的图书借阅记录
export function getMyBorrowList(id) {
  return request({
    url: `/borrow/user/${id}`,
    method: 'get',
  })
}

// 取消报名
export function cancelRegistration(lectureId) {
  return request({
    url: `/lectures/${lectureId}/register`,
    method: 'delete',
  })
}

// 讲座签到
export function checkinLecture(registrationId) {
  return request({
    url: `/lectures/checkin/${registrationId}`,
    method: 'post',
  })
}

// 取消预约
export function cancelReservation(reservationId) {
  return request({
    url: `/reservations/${reservationId}`,
    method: 'delete',
  })
}

// 预约签到
export function checkinReservation(reservationId) {
  return request({
    url: `reservations/${reservationId}/checkin`,
    method: 'post',
  })
}

// 归还图书
export function returnBook(data) {
  return request({
    url: '/borrow/return',
    method: 'post',
    data,
  })
}
